package com.example.springMVC.service.impl;

import com.example.springMVC.dao.ProviderMapper;
import com.example.springMVC.pojo.Provider;
import com.example.springMVC.pojo.User;
import com.example.springMVC.service.ProviderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProviderServiceImpl implements ProviderService {
    @Autowired
    ProviderMapper providerMapper;

    @Override
    public PageInfo<Provider> getProviderList(Integer currentPage, String proCode, String proName) {
        Map<String, Object> param = new HashMap<>();
        param.put("proCode", proCode);
        param.put("proName", proName);
        PageHelper.offsetPage((currentPage - 1) * 10, 10, true);
        List<Provider> providerList = providerMapper.getProviderList(param);
        PageInfo<Provider> info = new PageInfo<>(providerList);
        return info;
    }

    @Override
    public Provider getProviderById(long providerId) {
        Provider provider=  providerMapper.getProviderById(providerId);
        return provider;
    }

    @Override
    public boolean deleteProvider(long providerId) {
        return providerMapper.deleteProvider(providerId);
    }

    @Override
    public boolean updateProviderById(Provider provider) {
        return providerMapper.updateProviderById(provider);
    }

    @Override
    public boolean providerAdd(Provider provider) {
        providerMapper.providerAdd(provider);
        return true;
    }

    @Override
    public List<Provider> getproList() {
        List<Provider> providers = providerMapper.getproList();
        return providers;
    }
}
